#include <iostream>
#include <SDL.h>
#include "menu.h"
int SDL_main(int argc, char* argv[]){
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
        return 1;
    }
    SDL_Window *win = SDL_CreateWindow(
        "Chain Menu",
        SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
        MENU_WIDTH, MENU_HEIGHT,
        SDL_WINDOW_SHOWN
    );
    if (!win) {
        fprintf(stderr, "SDL_CreateWindow Error: %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }
    /* 简单事件循环：按 ESC 或关闭窗口即退出 */
    SDL_Event e;
    int quit = 0;
    menu_src_init(win);  // 初始化菜单源
    Menu *c= menu_create(NULL,NULL,"1.设置圈数",MENU_TYPE_ROOT, NULL,{0,0,0,0});  // 创建主菜单  
        menu_create(c,NULL,"1 x N",MENU_TYPE_CHILD, NULL,{1,0,1,1});  // 创建子菜单
        menu_create(c,NULL,"2 x N",MENU_TYPE_CHILD, NULL,{2,0,2,2});
        menu_create(c,NULL,"3 x N",MENU_TYPE_CHILD, NULL,{3,0,3,3});
        menu_create(c,NULL,"4 x N",MENU_TYPE_CHILD, NULL,{4,0,4,4});
        menu_create(c,NULL,"5 x N",MENU_TYPE_CHILD, NULL,{5,0,5,5});

    Menu *x= menu_create(NULL,NULL,"2.循迹PID",MENU_TYPE_ROOT, NULL,{0,0,0,0});  // 创建设置菜单
        menu_create(x,NULL,"循迹P值",MENU_TYPE_CHILD, NULL,{0,0,0,300});  // 创建子菜单
        menu_create(x,NULL,"循迹I值",MENU_TYPE_CHILD, NULL,{0,0,0,300});
        menu_create(x,NULL,"循迹D值",MENU_TYPE_CHILD, NULL,{0,0,0,300});
	Menu *y= menu_create(NULL,NULL,"3.云台PID",MENU_TYPE_ROOT, NULL,{0,0,0,0});  // 创建关于菜单
        menu_create(y,NULL,"云台P值",MENU_TYPE_CHILD, NULL,{0,0,0,100});  // 创建子菜单
        menu_create(y,NULL,"云台I值",MENU_TYPE_CHILD, NULL,{0,0,0,100});
        menu_create(y,NULL,"云台D值",MENU_TYPE_CHILD, NULL,{0,0,0,100});
    //menu_event();  // 初始化菜单事件
    while (!quit) {
        while (SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT) quit = 1;
            if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) quit = 1;
            else if (e.type == SDL_KEYDOWN){        
               menu_key_event(e.key.keysym.sym);
            }
        }
        menu_gui_event();  // 绘制菜单
        SDL_Delay(16);  // ≈ 60 FPS
    }

    SDL_DestroyWindow(win);
    SDL_Quit();
    return 0;
}
